/**
 * @(#) OverTimeSumProxy.as
 *
 * @date		2009. 02. 12.
 * @version		1.0
 * @author		Shin, Yunwoo
 * @description	휴가일수 Proxy - Proxy
 * 				구성원의 당해년도 휴가사용 내역을 조회 
 */
package com.skt.common_hr.work_nos.model
{
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.work_nos.WorkFacade;
	import com.skt.common_hr.work_nos.model.vo.OverTimeSumVO;
	
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
		
	public class OverTimeSumProxy extends CommonProxy
	{
		public static const NAME:String = "OverTimeSumProxy";
		
		public var sumList:ArrayCollection;
		
		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function OverTimeSumProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		
		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param pernr 사번
		 * @return void
		 */
		public function load(pernr:String, month:String):void
		{
			var param:Object = new Object();
			param["I_PERNR"] 		= pernr;
			param["I_MONTH"]		= month;
			
			loadData("Z_HR_0027", param, result, fault); 
		}
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function result(event:ResultEvent):void
		{
			if(retCode==0) {  
				sumList = parseOvertime(event.result.TTAB);
				facade.sendNotification(WorkFacade.LOAD_OVERTIME_SUM_COMPLETE, this);
			}
			else {
				facade.sendNotification(WorkFacade.LOAD_OVERTIME_SUM_FAILED, this);
			}
		}
		
		/**
		 * 서버에서 오류가 발생했을 처리
		 * 
		 * @param
		 * @return void
		 */
		private function fault(event:FaultEvent):void
		{
			facade.sendNotification(WorkFacade.LOAD_OVERTIME_SUM_FAILED, this);
		}
		
		
		
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Parsing functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 제증명서 종류 Code list
		 */
		private function parseOvertime(srcArr:ArrayCollection):ArrayCollection
		{
			var retArr:ArrayCollection = new ArrayCollection();
			for each(var rec:Object in srcArr) {
				var vo:OverTimeSumVO = new OverTimeSumVO;
				vo.WORKGBN 	= rec.WORKGBN;
				vo.TIME1 	= rec.TIME1;
				vo.TIME2 	= rec.TIME2;
				vo.TIME3 	= rec.TIME3;
				vo.TIME4 	= rec.TIME4;
				retArr.addItem(vo);
			}
			return retArr;	
		}
		
	}
}